<template>
  <div class="home">
    <div class="content">
      <div class="header">
        <el-page-header content="编辑页面" @back="goBack"></el-page-header>
      </div>
      <div class="selectMoudle">
        <div>
          <span class="text">模块</span>
          <el-radio-group v-model="editorData.radio1" fill="#1d2f70">
            <el-radio-button v-for="(item, index) in radio" :label="item.label" :key="index"></el-radio-button>
          </el-radio-group>
        </div>
        <div>
          <el-button class="sendBtn" @click="send">
            发布
            <i class="el-icon-upload el-icon--right"></i>
          </el-button>
        </div>
      </div>
      <div class="inputBox">
        <input type="text" placeholder="请写下你的问题" v-model="editorData.title" @change="onChangeEdit" />
      </div>
      <div class="editor">
        <textEditor
          @EditorChange="editorChange"
          :oldcontent="editorData.html"
          :oldremoveIds="editorData.deleImgId"
        ></textEditor>
      </div>
    </div>
  </div>
</template>

<script>
// import axios from "axios";
import textEditor from "@/components/quillEditor";
// import { textReplace } from "../../common/textReplace";
import { post_draft } from "@/api/draft";
export default {
  name: "Editor",
  data() {
    return {
      editorData: {
        radio1: "互帮互助",
        title: "",
        titleImageUrl: "",
        html: "",
        deleImgId: [],
        textReplace: "",
        deletTitleImageUrl: [],
        userId: this.$store.getters.userInfo._id
      },
      radio: [
        {
          name: "互帮互助",
          label: "互帮互助"
        }
      ]
      // timer: null
    };
  },
  components: {
    textEditor
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    editorChange(data) {
      this.editorData.html = data.html;
      this.editorData.deleImgId = data.removeIds;
      // this.editorData.textReplace = textReplace(data.html);
      console.log(this.editorData);
      this.onChangeEdit();
    },
    async onChangeEdit() {
      let editView = await post_draft(this.editorData);
      console.log("editView", editView);
      let edit_id = editView.data._id;
      this.$router.replace({
        path: "/editQuestion",
        query: {
          _id: edit_id
        }
      });
    },
    send() {
      if (this.editorData.title.replace(/\s+/g, "").length < 4) {
        return this.$alert("请完善问题描述,至少输入 4 个字", "提示", {
          confirmButtonText: "确定",
          callback: () => {}
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  background: #fff;
}
.content {
  width: 100%;
  .header {
    margin: 0 auto;
    width: 1200px;
    margin-top: 20px;
  }
  .selectMoudle {
    margin: 0 auto;
    width: 1200px;
    margin-top: 40px;
    display: flex;
    justify-content: space-between;
    .text {
      font-size: 20px;
      font-weight: 700;
      color: #757575;
      margin-right: 20px;
    }
    .sendBtn {
      background: #1d2f70;
      border: #1d2f70;
      color: #fff;
      &:hover {
        background: rgb(53, 89, 180);
      }
    }
  }
  .inputBox {
    margin: 0 auto;
    width: 1200px;
    margin-top: 30px;
    input {
      outline-style: none;
      outline-style: none;
      border: 0px;
      border-bottom: 2px solid #ccc;
      width: 1200px;
      padding: 13px 14px;
      font-size: 28px;
      font-weight: 700;
      font-family: "Microsoft soft";
      box-sizing: border-box;
    }
  }
  // margin-top: -19px;
  padding: 20px;
  box-sizing: border-box;
  .editor {
    min-height: 500px;
    margin-top: 40px;
  }
}
</style>
